package com.arcaneshift.model.validators;

import com.arcaneshift.model.request.AddCreatureCardRequest;
import com.arcaneshift.model.util.ElementType;
import com.arcaneshift.security.errors.CardError;
import com.arcaneshift.security.errors.GameError;
import com.common.model.abstracts.AbstractRequest;
import com.common.model.abstracts.AbstractValidator;
import com.common.security.abstracts.AbstractError;

public class AddCreatureCardValidator extends AbstractValidator {

	@Override
	public boolean validate(AbstractRequest abstractRequest) {
		AddCreatureCardRequest request = null;
		
		if (abstractRequest instanceof AddCreatureCardRequest) {
			request = (AddCreatureCardRequest) abstractRequest;
		} else {
			error = new GameError(AbstractError.INVALID_REQUEST);
			return false;
		}
		
		String name = request.getName();
		ElementType elementType = request.getElement();
		
		if (name == null) {
			error = new CardError(CardError.NO_NAME_PROVIDED);
			return false;
		}
		
		if (elementType == null) {
			error = new CardError(CardError.NO_ELEMENT_PROVIDED);
			return false;
		}
		
		if (name.length() < CreatureCardValidator.NAME_MIN_LENGTH ||
				name.length() > CreatureCardValidator.NAME_MAX_LENGTH) {
			error = new CardError(CardError.NAME_BAD_FORMAT);
			return false;
		}
		
		return true;
	}
}
